package collection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * List
 */
public class ListDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("fore");
        list.add("five");
        String e = list.get(2);
        System.out.println(e);//three
        System.out.println("-------");
        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }
        System.out.println("---------");
        Iterator<String> a = list.iterator();
        while(a.hasNext()){
            String str =a.next();
            System.out.println(str);
        }
        System.out.println("---------");

        for (String b:list) {
            System.out.println(b);
        }
        list.set(2, "3");
        System.out.println("list"+list);
        String c = list.set(2, "3");//将list中下标为2的元素设置为3，同时将原数据返回c
        System.out.println("list:"+c);
        list.remove(2);//删除下标为2的元素
        String s = list.remove(2);
        System.out.println(s);
        list.add(3, "dada");//在List下标为3的位置插入seven
        System.out.println(list);



    }
}
